using System;

[Serializable]
public class GenericAchivement : GGStoryAchivementBase
{
	[Serializable]
	public enum Type
	{
		Wins = 0,
		CoinsWon = 1,
		Setup = 2
	}

	public Type type;

	public int wins = 1;

	public int coinsWon = 100;

	public int giraffeDollars = 10;

	public bool restrictedToRoom;

	public MultiplayerRoomType room;

	public override int stepsRequired()
	{
		switch (type)
		{
		case Type.Wins:
			return wins;
		case Type.CoinsWon:
			return coinsWon;
		default:
			return wins;
		}
	}

	public override void ReportAll()
	{
		if (!isReported())
		{
			GGPlayerSettings.instance.walletManager.AddCurrency(CurrencyType.ggdollars, giraffeDollars);
		}
		base.ReportAll();
	}

	public override string GetDescription()
	{
		if (!string.IsNullOrEmpty(description))
		{
			return description;
		}
		if (type == Type.CoinsWon)
		{
			return "Win " + coinsWon + "(Coin) coins in multiplayer to continue!";
		}
		if (type == Type.Wins)
		{
			return "Win " + wins + " games in multiplayer to continue!";
		}
		return description;
	}

	public override void ReportSetupFinished()
	{
		if (!isFinished() && type == Type.Setup)
		{
			model.numStepsCompleted++;
			Save();
		}
	}

	public override void ReportGameFinished(GameFinishedParams finishedParams)
	{
		if (!isFinished() && (!restrictedToRoom || isInRoom(finishedParams, room)))
		{
			model.numStepsCompleted += getQuantity(finishedParams);
			Save();
			if (isFinished())
			{
				Analytics.instance.ReportStoryAchivementComplete(this);
			}
		}
	}

	private int getQuantity(GameFinishedParams finishedParams)
	{
		switch (type)
		{
		case Type.Wins:
			return finishedParams.isPlayerWinner ? 1 : 0;
		case Type.CoinsWon:
			return finishedParams.coinsWon;
		default:
			return finishedParams.coinsWon;
		}
	}

	private bool isInRoom(GameFinishedParams finishedParams, MultiplayerRoomType room)
	{
		if (finishedParams.initParameters.matchType != MatchType.MultiPlayer)
		{
			return false;
		}
		return finishedParams.initParameters.multiplayerParams.roomType == room;
	}
}
